package com.ibm.cps.sql.expression.function.scalar;

import com.ibm.util.ErrorCode;
import com.ibm.util.exception.CPSException;

public abstract class ExpressionFunction {

	public Object evaluate(Object... arguments) throws CPSException {
		int argumentCount = validArgumentCount();
		if(arguments.length != argumentCount)
			throw new CPSException(ErrorCode.INVALID_INPUT_ERROR, "Scala function " + this.getClass().getSimpleName() + " only takes one input");
		Object result = innerEvaluate(arguments);
		return result;
	}
	
	protected abstract int validArgumentCount();
	
	protected abstract Object innerEvaluate(Object... arguments);	
}
